package com.baipiao.permission.backend.config.security;

import com.alibaba.fastjson2.JSONObject;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;
import com.baipiao.permission.backend.entity.response.Res;
import com.baipiao.permission.backend.entity.response.ResStatusEnum;

import java.io.IOException;

/**
 * @Description: 登出成功处理逻辑
 */
@Component
public class CustomLogoutSuccessHandler implements LogoutSuccessHandler {
    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
                                Authentication authentication) throws IOException {
        String res = JSONObject.toJSONString(Res.success(ResStatusEnum.logout));// 200，退出成功
        httpServletResponse.setContentType("text/json;charset=utf-8");
        httpServletResponse.getWriter().write(res);
    }
}
